//
//  VideoViewController.m
//  New
//
//  Created by 才诗琦 on 16/1/17.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "VideoViewController.h"
#import "SliderView-Prefix.pch"
//#import <MediaPlayer/MediaPlayer.h>
@interface VideoViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *dataArr;

//@property(nonatomic, retain)UIButton *button;
// @property(nonatomic,strong)NSArray *videos;
@property(nonatomic, retain)VideoCell *cell;
@end

@implementation VideoViewController

- (void)dealloc
{
    [super dealloc];
    [_tableView release];
    [_dataArr release];
    
}


#pragma mark - 控制器视图方法
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    //tableView
    [self createTableView];
    
 //    [self.tableView addSubview:button];
//

}
//- (void)buttonClick:(UIButton *)br
//{
//    NSLog(@"ssss");
//}

- (void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 100) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    //注册cell
    [_tableView registerClass:[VideoCell class] forCellReuseIdentifier:@"cell"];
    
   
    
    //处理数据
    [self data];
    //管理内存
    [_tableView release];
    
//    //去掉下划线
//         self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
//    
//        [MBProgressHUD showMessage:@"正在努力加载中"];
    
         
}
///处理数据
- (void)data
{
    NSString *str = @"http://c.m.163.com/nc/video/home/0-10.html";
    
    [AFNModel GETWithHandler:str completion:^(id result) {
        self.dataArr = [VideoModel modelHandlerWithArray:result[@"videoList"]];
        [_tableView reloadData];
    }];
    
}
//cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return _dataArr.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    VideoModel *vi = _dataArr[indexPath.row];
  self.cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    [self.cell.imagView sd_setImageWithURL:[NSURL URLWithString:vi.cover]];
    self.cell.titleLabel.text = vi.title;
    self.cell.descriptionLabel.text = vi.Des;
    self.cell.playCountLabel.text = [vi.playCount stringValue];
    self.cell.timeLabel.text =[NSString stringWithFormat:@"%02d:%02d", [vi.length intValue] / 60, [vi.length intValue]% 60];

//    _cell.str  = vi.mp4_url;
//    NSLog(@"...%@", _cell.str);
    return self.cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
        return  310;
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    VideoModel *vi = _dataArr[indexPath.row];
//    _cell.str  = vi.mp4_url;
   
   }
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
